]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
gdm: port gnome-shell --gdm-mode to systemd
authorLennart Poettering <lennart@poettering.net>
Sat, 11 Feb 2012 00:38:41 +0000 (01:38 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 13 Feb 2012 22:17:09 +0000 (23:17 +0100)
ConsoleKit is obsoleted by systemd-logind. Accordingly, port
the current CK code to systemd. In order to be nice to
the Debian people fall back to CK if systemd is not found,
so that the code makes the best of whatever it runs on.

js/Makefile.am
js/gdm/powerMenu.js
js/gdm/systemd.js [new file with mode: 0644]

index 4c41bffee812879b5ce6f166b2838d8a554607f3..14a25b599913fd46363d602003f5258afd61611a 100644 (file)
@@ -7,6 +7,7 @@ nobase_dist_js_DATA =   \
        gdm/fingerprint.js      \
        gdm/loginDialog.js      \
        gdm/powerMenu.js        \
+       gdm/systemd.js          \
        extensionPrefs/main.js  \
        misc/config.js          \
        misc/docInfo.js         \
index efe1a8f93c65e7941ae90ccc029865a73cc8642a..59ebc42e60f9e6a4d4cdf21500e16039c2f6bd01 100644 (file)
@@ -22,6 +22,8 @@ const Lang = imports.lang;
 const UPowerGlib = imports.gi.UPowerGlib;
 
 const ConsoleKit = imports.gdm.consoleKit;
+const Systemd = imports.gdm.systemd;
+
 const PanelMenu = imports.ui.panelMenu;
 const PopupMenu = imports.ui.popupMenu;
 
@@ -32,6 +34,7 @@ const PowerMenuButton = new Lang.Class({
     _init: function() {
         this.parent('system-shutdown', null);
         this._consoleKitManager = new ConsoleKit.ConsoleKitManager();
+        this._systemdLoginManager = new Systemd.SystemdLoginManager();
         this._upClient = new UPowerGlib.Client();
 
         this._createSubMenu();
@@ -61,39 +64,75 @@ const PowerMenuButton = new Lang.Class({
     },
 
     _updateHaveShutdown: function() {
-        this._consoleKitManager.CanStopRemote(Lang.bind(this,
-            function(result, error) {
-                if (!error)
-                    this._haveShutdown = result;
-                else
-                    this._haveShutdown = false;
-
-                if (this._haveShutdown) {
-                    this._powerOffItem.actor.show();
-                } else {
-                    this._powerOffItem.actor.hide();
-                }
 
-                this._updateVisibility();
-            }));
+        if (Systemd.haveSystemd()) {
+            this._systemdLoginManager.CanPowerOffRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveShutdown = result != 'no';
+                    else
+                        this._haveShutdown = false;
+
+                    if (this._haveShutdown)
+                        this._powerOffItem.actor.show();
+                    else
+                        this._powerOffItem.actor.hide();
+
+                    this._updateVisibility();
+                }));
+        } else {
+            this._consoleKitManager.CanStopRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveShutdown = result;
+                    else
+                        this._haveShutdown = false;
+
+                    if (this._haveShutdown) {
+                        this._powerOffItem.actor.show();
+                    } else {
+                        this._powerOffItem.actor.hide();
+                    }
+
+                    this._updateVisibility();
+                }));
+        }
     },
 
     _updateHaveRestart: function() {
-        this._consoleKitManager.CanRestartRemote(Lang.bind(this,
-            function(result, error) {
-                if (!error)
-                    this._haveRestart = result;
-                else
-                    this._haveRestart = false;
-
-                if (this._haveRestart) {
-                    this._restartItem.actor.show();
-                } else {
-                    this._restartItem.actor.hide();
-                }
 
-                this._updateVisibility();
-            }));
+        if (Systemd.haveSystemd()) {
+            this._systemdLoginManager.CanRebootRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveRestart = result != 'no';
+                    else
+                        this._haveRestart = false;
+
+                    if (this._haveRestart)
+                        this._restartItem.actor.show();
+                    else
+                        this._restartItem.actor.hide();
+
+                    this._updateVisibility();
+                }));
+        } else {
+            this._consoleKitManager.CanRestartRemote(Lang.bind(this,
+                function(result, error) {
+                    if (!error)
+                        this._haveRestart = result;
+                    else
+                        this._haveRestart = false;
+
+                    if (this._haveRestart) {
+                        this._restartItem.actor.show();
+                    } else {
+                        this._restartItem.actor.hide();
+                    }
+
+                    this._updateVisibility();
+                }));
+        }
     },
 
     _updateHaveSuspend: function() {
@@ -132,12 +171,22 @@ const PowerMenuButton = new Lang.Class({
     },
 
     _onActivateRestart: function() {
-        if (this._haveRestart)
+        if (!this._haveRestart)
+            return;
+
+        if (Systemd.haveSystemd())
+            this._systemdLoginManager.RebootRemote(true);
+        else
             this._consoleKitManager.RestartRemote();
     },
 
     _onActivatePowerOff: function() {
-        if (this._haveShutdown)
+        if (!this._haveShutdown)
+            return;
+
+        if (Systemd.haveSystemd())
+            this._systemdLoginManager.PowerOffRemote(true);
+        else
             this._consoleKitManager.StopRemote();
     }
 });
diff --git a/js/gdm/systemd.js b/js/gdm/systemd.js
new file mode 100644 (file)
index 0000000..8dd73ab
--- /dev/null
@@ -0,0 +1,31 @@
+// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager'>
+<method name='PowerOff'>
+    <arg type='b' direction='in'/>
+</method>
+<method name='Reboot'>
+    <arg type='b' direction='in'/>
+</method>
+<method name='CanPowerOff'>
+    <arg type='s' direction='out'/>
+</method>
+<method name='CanReboot'>
+    <arg type='s' direction='out'/>
+</method>
+</interface>;
+
+const SystemdLoginManagerProxy = Gio.DBusProxy.makeProxyWrapper(SystemdLoginManagerIface);
+
+function SystemdLoginManager() {
+    return new SystemdLoginManagerProxy(Gio.DBus.system,
+                                        'org.freedesktop.login1',
+                                        '/org/freedesktop/login1');
+};
+
+function haveSystemd() {
+    return GLib.access("/sys/fs/cgroup/systemd", 0) >= 0;
+}